 use "$data\women_analysis.dta", clear
 
 global controlkid childageyears female genderage birthorder
 global controlwoman mbase_ageyears  fdstotal rantime ranerror numberkids
 global controlhh land members adults mbase_electrified  mbase_OB mbase_scheduled

 replace anyhelp=0 if pid_helpedinhome=="T"
 gen tutor=0 if anyhelp!=.
 replace tutor=1 if pid_helpedinhome=="T"

 gen groupchildage=.
 replace groupchildage=1 if childageyears<6
 replace groupchildage=2 if childageyears>=6 & childageyears<=12
 replace groupchildage=3 if childageyears>12 & childageyears<=16


 estimates clear
 ivregress 2sls admission_school (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if groupchildage==2, cluster(learnerid)
 est store admsnless12
 su admission_school if groupchildage==2 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 ivregress 2sls admission_school (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if groupchildage==3, cluster(learnerid)
 est store admsngreat12
 su admission_school if groupchildage==3 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'

 foreach i in 2 3{
  foreach v in  Dabsentschool dropoffatschool askingforhomework Dtimespenthomework womanhelphomework tutor{
  ivregress 2sls `v'  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if  groupchildage==`i' & admission_school==1, cluster(learnerid)
  estimates store `v'`i'
  su `v' if groupchildage==`i' & admission_school==1 & ITTanalysis==0
  estadd scalar controlmean=`r(mean)'
 }
 }


 ivregress 2sls Ddays_sick  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if  groupchildage==1, cluster(learnerid)
 est store daysless6
 su Ddays_sick if groupchildage==1 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 ivregress 2sls Ddays_sick  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if  groupchildage==2, cluster(learnerid)
 est store daysless12
 su Ddays_sick if groupchildage==2 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 ivregress 2sls Ddays_sick  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if  groupchildage==3, cluster(learnerid)
 est store daysgreat12
 su Ddays_sick if groupchildage==3 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 ivregress 2sls medicalhelp  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if Ddays_sick==0 & groupchildage==1, cluster(learnerid)
 est store medicalhelp1
 su medicalhelp if Ddays_sick==0 & groupchildage==1 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'
 ivregress 2sls medicalhelp  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if Ddays_sick==0 & groupchildage==2, cluster(learnerid)
 est store medicalhelp2
 su medicalhelp if Ddays_sick==0 & groupchildage==2 & ITTanalysis==0
 estadd scalar controlmean=`r(mean)'

 foreach i in 1 2 3{
  foreach v in placeofmedicalhelp presence_woman_treatment{
  ivregress 2sls `v'  (participatedTA_IV=ITTanalysis) i.strata $controlkid $controlwoman $controlhh if Ddays_sick==0 & groupchildage==`i', cluster(learnerid)
  est store `v'`i'
  su `v' if Ddays_sick==0 & groupchildage==`i' & ITTanalysis==0
  estadd scalar controlmean=`r(mean)'
  }
}
 esttab * using "$results/TableB8.xls", stat(controlmean N r2) keep (participatedTA_IV) b(3) se(3) replace

***FDR q-values
 *The FDR Q-values are computed following  Benjamini and Hochberg (1995) within each category.
 
 exit
 
 
